<?
//引入所有子系统信息
include_once("../../../../common/model/extender_import.php");
//引入系统设置
include_once("../../../../common/model/setting.php");


//同意加上and，然后去除左边的and就可以了。
if($_REQUEST['select_keywords'])
{
    $keywords=" and (title like '%".$_REQUEST['select_keywords']."%')";
    $keywords_url="&select_keywords=".$_REQUEST['select_keywords'];
}
else
{
    $keywords="";
    $keywords_url="";
}

if($_REQUEST['select_case_id'])
{
    $case=" and case_id = '".$_REQUEST['select_case_id']."'";
    $case_url="&select_case_id=".$_REQUEST['select_case_id'];
}
else
{
    $case="";
    $case_url="";
}

if($_REQUEST['select_principal_id'])
{
    $principal=" and principal = '".$_REQUEST['select_principal_id']."'";
    $principal_url="&select_principal_id=".$_REQUEST['select_principal_id'];
}
else
{
    $principal="";
    $principal_url="";
}

if($_REQUEST['select_status'] && $_REQUEST['select_status'] != '未完成')
{
    $status=" and status = '".$_REQUEST['select_status']."'";
    $status_url="&select_status=".$_REQUEST['select_status'];
}
else
{
    $status=" and status not in('已完成')";
    $status_url="";
}



if(($_REQUEST['select_departmentid'])&&($_REQUEST['select_departmentid']!="全部"))
{
    $departmentid=" and departmentid = '".$_REQUEST['select_departmentid']."'";
    $departmentid_url="&select_departmentid=".$_REQUEST['select_departmentid'];
}
else
{
    $departmentid="";
    $departmentid_url="";
}


if($_REQUEST['select_startday'])
{
    $start_date=$_REQUEST['select_startday']." 00:00:00";
    $start_date_str=" and enddate > '".$start_date."'";
    $start_date_url="&select_startday=".$_REQUEST['select_startday'];
}
else
{
    $start_date_str="";
    $start_date_url="";
}




if($_REQUEST['select_endday'])
{
    $end_date=$_REQUEST['select_endday']." 23:59:59";
    $end_date_str=" and enddate < '".$end_date."'";
    $end_date_url="&select_endday=".$_REQUEST['select_endday'];
}
else
{
    $end_date_str="";
    $end_date_url="";
}






if($sortorder)
{
    $sortorder="order by ".$sortorder;
}
else
{
    $sortorder="";
}







//生成翻页用连接地址。

//select_keywords=&select_paystatus=全部&select_graduate=全部&select_departmentid=7&select_license=全部&select_startday=2017-06-01&select_endday=2017-06-20
//select_keywords=欠费&select_start_date=2017-06-21&select_end_date=2017-06-18


$pagenumber_url = "&nowpageid=" . $_REQUEST['nowpageid'];
$sortby_url     = "&sortby=" . $_REQUEST['sortby'];
// $navitemed_url  = "&sys_part=" . $_REQUEST['sys_part'];
$system_part    = "&sys_part=" . $_REQUEST['sys_part'];
$term_nid       = "&term_nid=" . $_REQUEST['nid'];





$url_str=$keywords_url.$case_url.$principal_url.$status_url.$start_date_url.$end_date_url;



$select_str=$keywords.$case.$principal.$status.$start_date_str.$end_date_str;

//查询任务板块管理员
$setting = select_one_line_all_items($table_Prefix."task_setting","nid = '1'");

$manager_user_id = explode(',',$setting['manager_user_id']);

// 权限验证 管理员查看所有人的任务 普通用户只查看自己的任务
if(in_array($_SESSION['nid'],$manager_user_id)){
    $auth = '';
}else{
    $auth = "AND `principal` = ".$_SESSION['nid'];
}


//接收传递过来的分类id
$trans_nid   = addslashes($_REQUEST ['nid']);


//分类id存在，则说明要搜索板块中某一个分类的产品。
if ($trans_nid)
{
    $condition="and departmentid = '".$trans_nid."'";
}

$table = $table_Prefix . "task";
$sqlstr="SELECT COUNT(nid) FROM $table where (nid > '0') AND (is_del = '0')".$auth.$select_str;
$query = mysql_query($sqlstr);
$sum = mysql_result($query, 0);
?>











<?php
//设置翻页代码相关内容

$nowpageid = 1;
$detailnum = 25; //每页显示多少个产品


if ($_REQUEST ['nowpageid']) {
    $nowpageid = $_REQUEST ['nowpageid'];
} else {
    $nowpageid = 1;
}


//计算一下结果，从那条数据开始显示
$detailstar = ($nowpageid - 1) * $detailnum;


if ($sum) {

    if ($sum < $detailnum) {
        $page_count = 1;
        $detailnum = $sum;
    } //如果总数据量小于$Pagenum,（pagenum作为每页显示数据的条数，）那么只有一页,而pagenum也更改为sum 


    else if ($sum % $detailnum) {
        $page_count = (int)($sum / $detailnum) + 1;
    }
    //取总数据量除以每页数的余数 
    //如果有余数，则页数等于总数据量除以每页数的结果取整再加一


    else {
        $page_count = $sum / $detailnum;
    }
    //如果没有余数，则页数等于总数据量除以每页数的结果 

} else {
    $page_count = 0;
    $detailnum = 0;
}


$lastpage = $page_count;
$prepage = $nowpageid - 1;
$nextpage = $nowpageid + 1;


if ($nowpageid == 1) {
    $prepage = 1;
}


if ($nowpageid == $page_count) {

    if ($sum <= $detailnum) //总数数据少于每页显示数目，就把循环改成总数数目
    {
        $detailnum = $sum;
        $nextpage = $nowpageid;
    } else {
        $nextpage = $nowpageid;
        $detailnum = fmod($sum, $detailnum);
        if ($detailnum == 0) //这个if是因为当数据正好30条，能除尽的话，最后一页就会因为fmod能整除的缘故，最后一页不显示数据
        {
            $detailnum = $plate['page_list_num'];
        }
    }
    //如果现在页数等于总页数（总页数上面求出，最后一页不够循环数的时候），那么最后一页的detailnum就会等于余下数据(不足一页)的数目.

}

?>




<?
//设置需要搜索的表格的排序项和升降项
$sort_by = "enddate";
$sort_order = "asc";
//设置需要搜索的表格的排序项和升降项


if ($_REQUEST ['sortby']) {
    $sort_by = $_REQUEST ['sortby'];
}


if ($_REQUEST ['sortorder']) {
    $sort_order = $_REQUEST ['sortorder'];
}

//按照任务截止日期的升序排列，超时越多的越靠前

$sqlstr="select * from $table where (nid > '0') AND (is_del = '0')".$auth.$select_str." ORDER BY $sort_by $sort_order limit $detailstar , $detailnum";

$result = mysql_query($sqlstr);

while ($row = mysql_fetch_array($result)) {

    $comment_list = select_lines_all_items($table_Prefix.'task_comment','nid desc',' task_id ='.$row['nid']);
    $row['notice_show'] = 0;


    if($comment_list){
        foreach($comment_list as $comment){
            $notice_member = explode(',',$comment['notice_member']);
            $notice_member_read = explode(',',$comment['notice_member_read']);
            if(in_array($_SESSION['nid'],$notice_member)){
                if(!in_array($_SESSION['nid'],$notice_member_read)){
                    $row['notice_show'] = 1;
                }
            }
        }
    }
    $detail[]           = $row;
}
mysql_close($con);

?>








